package com.zwim.common.enums;

/**
 * 数据包类型
 *
 * @author zhenjiang.gong
 * @date
 */
public enum PacketTypeEnum {
    OPEN(0),
    CLOSE(1),
    PING(2),
    PONG(3),
    MESSAGE(4),
    UPGRADE(5),
    NOOP(6),
    CONNECT(0, true),
    DISCONNECT(1, true),
    EVENT(2, true),
    ACK(3, true),
    ERROR(4, true),
    BINARY_EVENT(5, true),
    BINARY_ACK(6, true);

    public static final PacketTypeEnum[] VALUES = values();
    private final int value;
    //是否是内部
    private final boolean inner;

    PacketTypeEnum(int value) {
        this(value, false);
    }

    PacketTypeEnum(int value, boolean inner) {
        this.value = value;
        this.inner = inner;
    }

    public int getValue() {
        return value;
    }

    public static PacketTypeEnum valueOf(int value) {
        for (PacketTypeEnum type : VALUES) {
            if (type.getValue() == value && !type.inner) {
                return type;
            }
        }
        throw new IllegalStateException();
    }

    public static PacketTypeEnum valueOfInner(int value) {
        for (PacketTypeEnum type : VALUES) {
            if (type.getValue() == value && type.inner) {
                return type;
            }
        }
        throw new IllegalArgumentException("Can't parse " + value);
    }
}
